package com.burgeon.backend.SHOPBACKEND.controller;


import com.burgeon.backend.SHOP.service.ex.AddAddressExceptionApp;

import com.burgeon.backend.SHOP.service.ex.LoggingExceptionApp;
import com.burgeon.backend.SHOP.service.ex.OrderExceptionApp;

import com.burgeon.backend.SHOPBACKEND.service.ex.*;
import com.burgeon.backend.stsutil.ResponseResult;
import org.apache.tomcat.util.http.fileupload.FileUploadException;
import org.springframework.web.bind.annotation.ExceptionHandler;


/**
 * 控制器类的基类
 */

public class BaseController {

    /**
     * 处理请求时，用于表示操作正确的代码
     */

    public static final int SUCCESS = 200;


    @ExceptionHandler({ServiceException.class,
            FileUploadException.class})
    public ResponseResult<Void>
    handleException(Exception e) {
        // 声明返回对象
        ResponseResult<Void> rr = new ResponseResult<Void>();
        // 在返回对象封装错误提示的文字
        rr.setMessage(e.getMessage());

        if (e instanceof GetUserDataException) {
            rr.setState(420);
        } else if (e instanceof InsertException) {
            rr.setState(520);
        } else if (e instanceof UserNotFoundException) {
            rr.setState(401);
        } else if (e instanceof PasswordNotMatchException) {
            rr.setState(402);
        } else if (e instanceof LoadingException) {
            rr.setState(485);
        } else if (e instanceof UpDataException) {
            rr.setState(486);
        } else if (e instanceof DeleteException) {
            rr.setState(487);
        } else if (e instanceof PhoneException) {
            rr.setState(488);
        } else if (e instanceof SendCodeException) {
            rr.setState(490);
        } else if (e instanceof ErrorDataException) {
            rr.setState(527);
        } else if (e instanceof RepetitionException) {
            rr.setState(585);
        } else if (e instanceof LoggingExceptionApp) {
            rr.setState(489);
        } else if (e instanceof AddAddressExceptionApp){
            rr.setState(526);
        } else if (e instanceof OrderExceptionApp){
            rr.setState(529);
        } else if (e instanceof UploadException){
            rr.setState(530);
        }else if (e instanceof DataNotFoundException){
            rr.setState(531);
        }else if (e instanceof InexistenceException){
            rr.setState(199);
        }


        return rr;
    }
}







